package com.webbei.HAO.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.webbei.HAO.service.ChSer;
import com.webbei.myCustom.action.MyUtil;

public class Register extends ActionSupport {
	private String email;
	private String password;
	private String username;
	private String thirdPartyId;
	private String nickname;
	//private String confirm;
	private ChSer ser;
	//private Integer id;

	public String execute() {
	
		username=MyUtil.format(username);
		System.out.println(username+"----usernaem");
		nickname = MyUtil.format(nickname);
		System.out.println("nickname:"+nickname);
		String path=ServletActionContext.getServletContext().getRealPath("/");
		String userpath=path+"img/resources/webbeiUserInfo/"+username;
		ser.createfile(userpath);
		
		String jin="img/resources/webbeiUserInfo/"+username+"/userTouxiang/"+"touxiang.jpg";
    	MyUtil.copy(path+"publicTouxiang/touxiang.jpg", userpath+"/userTouxiang/");
		
		int userid = ser.register(email,password,username,jin,nickname);
		
		ser.insertcuslimit(username);
		ser.insertUserhot(username);
		ser.insertLovecar(userid);
		System.out.println("userid-----:"+userid);
		System.out.println("third:"+username);
		if(!thirdPartyId.equals("0")){
			
			Map<String,String> map=new HashMap<String,String>();
			map.put("thirdId", thirdPartyId);
			map.put("username", username);
			System.out.println(map+"------map");
			ser.insertThirdParty(map);
		}
		Map<String, Object> session=ServletActionContext.getContext().getSession();
		session.put("username", username);
		
		
	
		return SUCCESS;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}


	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

    public ChSer getSer() {
		return ser;
	}

	public void setSer(ChSer ser) {
		this.ser = ser;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getThirdPartyId() {
		return thirdPartyId;
	}

	public void setThirdPartyId(String thirdPartyId) {
		this.thirdPartyId = thirdPartyId;
	}


	public String getNickname() {
		return nickname;
	}


	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	

}
